﻿@model MiniShoppingCartModel
@using Nop.Web.Models.ShoppingCart;
@*<span class="flyout-cart-quantity @if (Model.TotalProducts <= 0) { <text>zero</text> }">@Model.TotalProducts</span>*@
<div class="cart-wrapper">
    <div class="cart-content">
        @if (Model.PendingShoppingOrdersCount > 0 && Model.PendingShoppingOrder != null)
        {
            <div class="flyout-cart-top flyout-cart-section flyout-cart-pending-orders">
                @Html.Raw(string.Format(T("ShoppingCart.Mini.PendingOrder.HasPendingOrder").Text, Model.PendingShoppingOrderAmount))
                <div>
                <input type="button" onclick="AjaxCart.removependingorderfromcart('@Url.Action("RemovePendingOrder", "ShoppingCart", new { area = "Commerce" })','@Model.PendingShoppingOrder.Id')" class="btn btn-normal delete-order" value="@T("ShoppingCart.Mini.PendingOrder.DeleteOrder")"><a href="@Url.RouteUrl("CheckoutOnePage", new { type = "o", Id = Model.PendingShoppingOrder.Id })" class="btn btn-danger">@T("ShoppingCart.Mini.PendingOrder.ContinueOrder")</a>
                </div>
                <div class="clear"></div>
                @if (Model.PendingShoppingOrdersCount > 1)
                {
                    <a href="@Url.RouteUrl("CustomerOrders")">@Html.Raw(string.Format(T("ShoppingCart.Mini.PendingOrder.ViewAllOrders").Text, Model.PendingShoppingOrdersCount))</a>
                }
            </div>
        }
        <div class="flyout-cart-top flyout-cart-section">
            @if (Model.TotalProducts == 0)
            {
                @Html.Raw(T("ShoppingCart.Mini.Empty").Text);
            }
            else
            {
                if (Model.TotalProducts == 1)
                {
                    @Html.Raw(string.Format(T("ShoppingCart.Mini.OneItemFull").Text, string.Format("<a href=\"{0}\" class=\"items\">{1}</a>", Url.RouteUrl("ShoppingCart"), T("ShoppingCart.Mini.OneItem").Text)))
                }
                else
                {
                    @Html.Raw(string.Format(T("ShoppingCart.Mini.SeveralItemsFull").Text, string.Format("<a href=\"{0}\" class=\"items\">{1}</a>", Url.RouteUrl("ShoppingCart"), string.Format(T("ShoppingCart.Mini.SeveralItems").Text, Model.TotalProducts))))
                }

            }
            <a class="minicart-shoppingcart" href="@Url.RouteUrl("ShoppingCart")">@T("ShoppingCart.Mini.ViewCart")</a>
        </div>
        @if (Model.TotalProducts > 0)
        {
            if (Model.Items.Count > 0)
            {
                <div class="flyout-cart-items flyout-cart-section">
                    <div class="flyout-cart-items-wrapper">
                        <table class="items-table">
                            <tbody>
                                @for (int i = 0; i < Model.Items.Count; i++)
                                {
                                    var item = Model.Items[i];
                                    <tr class="item @(i == 0 ? "first" : null) @(i % 2 == 0 ? "odd" : "even")" data-id="@Model.Items[i].ProductId" data-pid="@Model.Items[i].Id" data-quantity="@Model.Items[i].Quantity" onclick="window.location.href = '@Url.RouteUrl("Product", new { SeName = item.ProductSeName })'">
                                        @if (Model.ShowProductImages)
                                        {
                                            <td class="item-picture">
                                                <div class="cart-item-image">
                                                    <img alt="@item.Picture.AlternateText" src="@item.Picture.ImageUrl" title="@item.Picture.Title" />
                                                </div>
                                            </td>
                                        }
                                        <td class="item-info">
                                            <div class="name">
                                                <a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })">@item.ProductName</a>
                                            </div>
                                            @if (!String.IsNullOrEmpty(item.AttributeInfo))
                                            {
                                                <div class="attributes">
                                                    @Html.Raw(item.AttributeInfo)
                                                </div>
                                            }
                                            <div class="quantity">@T("ShoppingCart.Mini.Quantity"): @item.Quantity</div>
                                        </td>
                                        <td class="item-price">
                                            <div class="item-subtotal">@item.Subtotal</div>
                                            <div class="item-remove"><a title="@T("Common.Remove")" href="@Url.RouteUrl("RemoveProductFromCart", new { productVariantId = item.Id, shoppingCartTypeId = 1 })" onclick="AjaxCart.removeproductfromcart('@Url.RouteUrl("RemoveProductFromCart", new { productVariantId = item.Id, shoppingCartTypeId = 1 })', @item.ProductId, $(this), event); return false;"><i class="fa fa-trash-o"></i></a></div>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </div>

            }

            <div class="flyout-cart-bottom flyout-cart-section">
                <div class="flyout-cart-subtotal">@T("ShoppingCart.Totals.SubTotal"): @Model.SubTotal</div>

                <div class="flyout-cart-button">
                    @if (Model.DisplayCheckoutButton)
                    {
                        @Html.RouteLink(T("Checkout").Text, "CheckoutOnePage", new { type = "s", Id = 1 }, new { @class = "flyout-cart-checkout btn btn-danger" })
                    }
                    <div class="clear"></div>
                </div>
            </div>
        }
    </div>
    <script>
        $(document).ready(function () {
            var totalProducts = parseInt("@Model.TotalProducts");
            if (!isNaN(totalProducts) && totalProducts > 0) {
                if (totalProducts < 100) {
                    $(".cart-quantity").text(totalProducts).show();
                } else {
                    $(".cart-quantity").text("!").show();
                }
            } else {
                $(".cart-quantity").text("").hide();
            }
            $(".cart-pending-order").removeClass("pending").text("@Model.PendingShoppingOrdersCount");
            @if (Model.PendingShoppingOrdersCount > 0)
            {
                <text>
            $(".cart-pending-order").addClass("pending");
            </text>
            }
        });
    </script>
</div>